package cn.training.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import cn.training.bean.UserBean;
import cn.training.service.HelloWorldService;


@Controller("HelloWorldController")
@RequestMapping("/")
public class HelloWorldController {

	private static final String userdelete = null;
	@Autowired
	HelloWorldService helloWorldService;
	
    @RequestMapping(value = "/", method = RequestMethod.GET)
    public String index(Model model) {
        return "helloWorld";
    }
    
    @RequestMapping(value = "/init", method = RequestMethod.POST)
    public String initLogin(UserBean userBean, Model model) {
    	
    	//UserBean result = helloWorldService.searchUser(userBean);
    	List<UserBean> result=helloWorldService.searchUser(userBean);
    	model.addAttribute("list", result);
        return "login";
    }
    @RequestMapping(value = "/init", method = RequestMethod.POST,params="insert")
    public String initinsert(UserBean userinsert, Model model) {
    	
    	int insert=helloWorldService.insert(userinsert);
        return "login";
    }
   @RequestMapping(value = "/init", method = RequestMethod.POST,params="update")
   public String initupdate(UserBean userupdate, Model model) {
    	
    	int update=helloWorldService.update(userupdate);
      return "login";
   }
   @RequestMapping(value = "/delete", method = RequestMethod.GET)
   public String initdelete(UserBean userBean, Model model) {
    	
    	int delete=helloWorldService.delete(userBean);
    	List<UserBean> result=helloWorldService.searchUser(userBean);
    	model.addAttribute("list",result);
        return "login";
   }
}
